<?php

if (!(defined('IN_IA'))) 
{
	exit('Access Denied');
}

class Database_MxShopPage extends WebPage
{

	function main()
	{
	    global $_W;

	    pdo_query("

	        CREATE TABLE IF NOT EXISTS `ims_mx_shop_user` (
              `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
              `realname` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '真实姓名',
              `mobile` VARCHAR (11) NOT NULL DEFAULT '' COMMENT '登录手机',
              `pwd` CHAR (32) NOT NULL DEFAULT '' COMMENT 'md5密码',
              `salt` VARCHAR (32) NOT NULL DEFAULT '' COMMENT '密码加盐字符',
              `credit1` DECIMAL (10,2) NOT NULL DEFAULT '0.00' COMMENT '通用积分',
              `credit2` DECIMAL (10,2) NOT NULL DEFAULT '0.00' COMMENT '通用余额',
              `parentid` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '上级id',
              `isstore` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '是否是门店id',
              `groupid` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '组id',
              `levelid` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '等级id',
              `country` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '国家',
              `province` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '省',
              `city` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '市',
              `area` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '区域',
              `nickname` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '昵称',
              `avatar` VARCHAR (255) NOT NULL DEFAULT '' COMMENT '头像',
              `gender` TINYINT (2) UNSIGNED NOT NULL DEFAULT '0' COMMENT '0未知1男2女',
              `idcard` VARCHAR (24) NOT NULL DEFAULT '' COMMENT '身份证',
              `idcardimg` TEXT NOT NULL DEFAULT '' COMMENT '身份证图片',
              `weixin` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '微信号',
              `alipay` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '支付宝账号',
              `diymaxcredit` INT (11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '积分上限',
              `maxcredit` INT (11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '积分上限',
              `isblack` TINYINT (2) UNSIGNED NOT NULL DEFAULT '0' COMMENT '是否黑名单',
              `status` TINYINT (2) UNSIGNED NOT NULL DEFAULT '1' COMMENT '1可用0不可用',
              `lasttime` INT (11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '最后登录时间',
              `createtime` INT (11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间',
              PRIMARY KEY (`id`),
              KEY `parentid` (`parentid`)
            ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
            
            CREATE TABLE IF NOT EXISTS `ims_mx_shop_userinfo` (
              `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
              `uid` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '用户id',
              `uniacid` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '公众号id',
              `openid` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '第三方登录openid',
              `credit1` DECIMAL(10,2) NOT NULL DEFAULT '0.00' COMMENT '平台积分',
              `credit2` DECIMAL(10,2) NOT NULL DEFAULT '0.00' COMMENT '平台余额',
              `avatar` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '头像',
              `nickname` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '昵称',
              `realname` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '真实姓名',
              `uv` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '活跃度',
              `country` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '国家',
              `province` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '省',
              `city` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '市',
              `area` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '区域',
              `gender` TINYINT (2) UNSIGNED NOT NULL DEFAULT '0' COMMENT '0未知1男2女',
              `isuser` TINYINT (2) UNSIGNED NOT NULL DEFAULT '0' COMMENT '是否绑定用户',
              `isblack` TINYINT (2) UNSIGNED NOT NULL DEFAULT '0' COMMENT '黑名单',
              `lasttime` INT (11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '最后登录时间',
              `createtime` INT (11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间',
              PRIMARY KEY (`id`),
              KEY `userid` (`uid`),
              KEY `user_openid` (`openid`)
            ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
            
            CREATE TABLE IF NOT EXISTS `ims_mx_shop_user_level` (
              `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
              `uniacid` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '公众号id',
              `level` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '等级',
              `levelname` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '等级名称',
              `ordermoney` DECIMAL(10,2) NOT NULL DEFAULT '0.00' COMMENT '订单金额',
              `discount` TINYINT (3) UNSIGNED NOT NULL DEFAULT '0' COMMENT '折扣',
              `ordercount`  INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '订单总数',
              `status`  TINYINT(2) UNSIGNED NOT NULL DEFAULT '0' COMMENT '状态',
              `createtime` INT (11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间',
              PRIMARY KEY (`id`)
            ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
             
            CREATE TABLE IF NOT EXISTS `ims_mx_shop_user_group` (
              `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
              `uniacid` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '公众号id',
              `groupname` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '组名称',
              `createtime` INT (11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间',
              PRIMARY KEY (`id`)
            ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
            
            CREATE TABLE IF NOT EXISTS `ims_mx_shop_user_log` (
              `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
              `uniacid` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '公众号id',
              `uid` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '会员openid',
              `type` TINYINT (3) UNSIGNED NOT NULL DEFAULT '1' COMMENT '1充值',
              `logno` VARCHAR (50) NOT NULL DEFAULT '' COMMENT '订单号',
              `title` VARCHAR (255) NOT NULL DEFAULT '' COMMENT '标题',
              `money` DECIMAL (12,2) NOT NULL DEFAULT '0.00' COMMENT '金额',
              `realmoney` DECIMAL (12,2) NOT NULL DEFAULT '0.00' COMMENT '真实金额',
              `rechargetype` TINYINT (3) UNSIGNED NOT NULL DEFAULT '0' COMMENT '充值支付类型',
              `couponid` INT (11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '优惠券id',
              `couponmoney` DECIMAL (12,2) NOT NULL DEFAULT '0.00' COMMENT '优惠券金额',
              `isborrow` TINYINT (3) UNSIGNED NOT NULL DEFAULT '0' COMMENT '他人支付',
              `borrowopenid` VARCHAR (3) NOT NULL DEFAULT '' COMMENT '支付openid',
              `bankname` VARCHAR (255) NOT NULL DEFAULT '' COMMENT '银行名',
              `bankcard` VARCHAR (50) NOT NULL DEFAULT '' COMMENT '银行卡号',
              `realname` VARCHAR (50) NOT NULL DEFAULT '' COMMENT '银行卡姓名',
              `remark` VARCHAR (255) NOT NULL DEFAULT '' COMMENT '备注',
              `createtime` INT (11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间',
              `status` TINYINT (3) UNSIGNED NOT NULL DEFAULT '0' ,
              PRIMARY KEY (`id`),
              KEY `user_id` (`uid`)
            ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
            
	    ");

//        pdo_query("
//            CREATE TABLE IF NOT EXISTS `ims_mx_shop_user_address` (
//              `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
//              `uid` INT (11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '会员uid',
//              `realname` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '收货人',
//              `mobile` VARCHAR (20) NOT NULL DEFAULT '' COMMENT '手机号',
//              `country` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '国家',
//              `province` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '省',
//              `city` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '市',
//              `area` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '区',
//              `address` TEXT NOT NULL DEFAULT '' COMMENT '详细地址',
//              `isdefault` TINYINT (1) UNSIGNED NOT NULL DEFAULT '0' COMMENT '是否默认',
//              `deleted` TINYINT (1) UNSIGNED NOT NULL DEFAULT '0' COMMENT '是否删除',
//              `deletedtime` INT (11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '删除时间',
//              `createtime` INT (11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间',
//              PRIMARY KEY (`id`),
//              KEY `user_openid` (`openid`)
//            ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
//
//             CREATE TABLE IF NOT EXISTS `ims_mx_shop_user_cart` (
//              `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
//              `uniacid` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '公众号id',
//              `openid` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '会员openid',
//              `goodsid` INT (11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '商品id',
//              `total` INT (10) UNSIGNED NOT NULL DEFAULT '' COMMENT '总数',
//              `marketprice` DECIMAL (10,2) NOT NULL DEFAULT '0.00' COMMENT '价格',
//              `merchid` INT (11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '商户id',
//              `deleted` TINYINT (1) UNSIGNED NOT NULL DEFAULT '0' COMMENT '是否删除',
//              `deletedtime` INT (11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '删除时间',
//              `createtime` INT (11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间',
//              PRIMARY KEY (`id`),
//              KEY `user_openid` (`openid`)
//            ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
//
//            CREATE TABLE IF NOT EXISTS `ims_mx_shop_user_history` (
//              `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
//              `uniacid` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '公众号id',
//              `openid` VARCHAR (100) NOT NULL DEFAULT '' COMMENT '会员openid',
//              `goodsid` INT (11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '商品id',
//              `merchid` INT (11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '商户id',
//              `deleted` TINYINT (1) UNSIGNED NOT NULL DEFAULT '0' COMMENT '是否删除',
//              `deletedtime` INT (11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '删除时间',
//              `createtime` INT (11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间',
//              PRIMARY KEY (`id`),
//              KEY `user_openid` (`openid`)
//            ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
//        ");
        if(pdo_tableexists('mx_shop_platform'))
        {
            if (!pdo_fieldexists('mx_shop_platform', 'manageid')) {
                pdo_query("ALTER TABLE " . tablename('mx_shop_platform') . " ADD `manageid` int(11) unsigned NOT NULL DEFAULT 0;");
            }
        }

//        $n = mt_rand(1,500);
//        $a = pdo_fetch('SELECT * FROM '.tablename('ewei_shop_cgc_order').' LIMIT '.$n.',1');
//
//        unset($a['id']);
//        unset($a['openid']);
//
//        $a['uid'] = 7;
//        $a['mendian_id'] = 1;
//        $a['goods_id'] = 1;
//        pdo_insert('mx_shop_service_order', $a);


	    message('执行成功！');
	}

}
